package com.wanxi.controller;

import com.alibaba.fastjson2.JSONObject;
import com.wanxi.dto.ResultDTO;
import com.wanxi.service.NavService;
import com.wanxi.vo.NavVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
/**
 * @author Chengbo Zhang
 */
@RestController
@RequestMapping("/admin/nav")
@CrossOrigin(origins = "http://localhost:8081")
public class NavController {
    @Autowired
    NavService navService;

    @PutMapping("/add")
    @PreAuthorize("hasAuthority('insertNav')")
    public ResultDTO addNav(NavVO navVO){
        return navService.addNav(navVO);
    }

    @DeleteMapping("/delete")
    @PreAuthorize("hasAuthority('deleteNav')")
    public ResultDTO deleteNav(NavVO navVO){
        return navService.delete(navVO);
    }

    @GetMapping("/findAll")
    public ResultDTO findAllNav(){
        return navService.findAllNav();
    }

    @PostMapping("/findById")
    public ResultDTO findNavById(NavVO navVO){
        return navService.findNavById(navVO);
    }

    @PostMapping("/updateEnable")
    @PreAuthorize("hasAuthority('updateNav')")
    public ResultDTO updateNavEnable(NavVO navVO){
        return navService.updateEnable(navVO);
    }

    @PostMapping("/update")
    @PreAuthorize("hasAuthority('updateNav')")
    public ResultDTO updateNav(NavVO navVO){
        return navService.update(navVO);
    }
}
